package com.geek.factory.mapper;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.geek.factory.entity.User;
import org.apache.ibatis.annotations.*;
import com.github.yulichang.base.MPJBaseMapper;
import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2025-06-19
 */
public interface UserMapper extends MPJBaseMapper<User> {

    /**
     * ${ew.customSqlSegment}:拼接where后的语询(在动态sq|中请勿处于标签内)
     * ${ew.sqlSelect} :拼接select SQL主体
     * ${ew.sqlSet} :拼接update主体
     * ${ew.sqlSegment} :拼接where后的语询
     */
    @Select("select * from user ${ew.customSqlSegment}")
    @Results({
            @Result(id = true , property = "id" , column = "id"),
            @Result(column = "id" , property = "roles" , javaType = Set.class ,
                    many = @Many(select = "com.geek.factory.mapper.RoleMapper.selectRoleByUserId"))
    })
    Page<User> selectAllPage(@Param("page") Page<User> page, @Param("ew") LambdaQueryWrapper<User> wrapper);

    @Select("SELECT * FROM user WHERE phone = #{phone} LIMIT 1")
    User selectByPhone(String phone);
}
